use TestHelper;
use Map;
use EntityBagTestHelper;

sub getSomeTiles{
    my ($w, $h) = (shift, shift);
    my @columns = ();
    for(my $x = 0; $x<$w; $x++){
	@column = ();
	for(my $y = 0; $y<$h; $y++){
	    # Just plain ground for now
	    $tile = Ground->spawn();
	    push(@column, $tile);
	} # y
	push(@columns, \@column);
    } # x
    return \@columns;
}

sub testDimensions{
    my $map = shift;
    my ($w, $h) = (shift, shift);

    print "Probando dimensiones: $w X $h\n";
    if($map->width == $w){
	print "    W=$w OK\n";
    }else{
	print "--->ERROR: W = ".$map->width." != ".$w."\n";
    }
    my $realw = scalar(@{$map->tiles});
    if( $realw == $w){
	print "    REAL W=$realw OK\n";
    }else{
	print "--->ERROR: REAL W = ".$realw." != ".$w."\n";
    }

    if($map->height == $h){
	print "    H=$h OK\n";
    }else{
	print "--->ERROR: H = ".$map->height." != ".$h."\n";
    }

    my $x;
    my $realh;
    my $realherr = 0;
    for($x = 0; $x<$w; $x++){
	$realh = scalar(@{$map->tiles->[$x]});
	if( $realh != $h){
	    print "--->ERROR: REAL H = ".$realh." != $h in column # $x\n";
	    $realherr = 1;
	}
    }
    print "    REAL H = $realh OK\n" unless $realherr;
} # testDimensions

sub testUniformTileset{
    my $map = shift;
    my $tileClassName = shift;

    print "Probando celdas\n";
    my $tile;
    my $typeerr = 0;
    for(my $x = 0; $x<$map->width; $x++){
	for(my $y = 0; $y<$map->height; $y++){
	    $tile = $map->tiles->[$x][$y];
	    if(ref($tile) != $tileClassName){
		$typeerr = 1;
		print "--->ERROR: ".(ref($tile))." != $tileClassName en $x ; $y \n";
	    }
	} # y
    } # x
    
    print "    Tipo $tileClassName OK\n" unless($typeerr);
}

sub testNoDimensionMutation{
    my ($map, $w, $h) = (shift, shift, shift);

    print "Probando dimensiones no mutables \n";
    $map->width($w - 1);
    if($map->width == $w){
	print "    W OK\n";
    }else{
	print "--->ERROR: W = ".$map->width." != ".$w."\n";
    }

    $map->height($h - 1);
    if($map->height == $h){
	print "    H OK\n";
    }else{
	print "--->ERROR: H = ".$map->height." != ".$h."\n";
    }
    
}


sub printMap{
    my $map = shift;

    for(my $j = 0; $j < $map->height; $j++){
	for(my $i = 0; $i < $map->width; $i++){
	    print $map->tiles->[$i][$j]->pic;
	} # i
	print "\n";
    } # j	    


}

1;
